package com.bestvike.stone.core.threading.inherit;

import com.bestvike.stone.core.threading.WaitRunnable;
import com.bestvike.stone.core.threading.holder.RawThreadLocalsHolder;
import org.springframework.util.Assert;

/**
 * Created by 许崇雷 on 2018/8/13.
 */
public final class InheritWaitRunnable<TState> extends InheritAction implements Runnable {
    private final WaitRunnable<TState> waitCallback;
    private final TState state;

    public InheritWaitRunnable(WaitRunnable<TState> waitCallback, TState state) {
        Assert.notNull(waitCallback, "waitCallback can not be null");
        this.waitCallback = waitCallback;
        this.state = state;
    }

    @Override
    public void run() {
        try (RawThreadLocalsHolder ignored = this.ready()) {
            this.waitCallback.run(this.state);
        }
    }
}
